package torque.generated;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.map.TableMap;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;





/**
 * Armes
 *
 * This class was autogenerated by Torque on:
 *
 * [Tue Mar 24 08:44:00 CET 2009]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to Arme
 */
public abstract class BaseArme extends BaseObject
{
    /** Serial version */
    private static final long serialVersionUID = 1237880640559L;

    /** The Peer class */
    private static final ArmePeer peer =
        new ArmePeer();


    /** The value for the idObjet field */
    private int idObjet;

    /** The value for the nom field */
    private String nom;

    /** The value for the bonusattaque field */
    private int bonusattaque;

    /** The value for the bonusdegat field */
    private int bonusdegat;

    /** The value for the bonusesquive field */
    private int bonusesquive;

    /** The value for the portee field */
    private int portee;

    /** The value for the type field */
    private int type;


    /**
     * Get the IdObjet
     *
     * @return int
     */
    public int getIdObjet()
    {
        return idObjet;
    }


    /**
     * Set the value of IdObjet
     *
     * @param v new value
     */
    public void setIdObjet(int v) throws TorqueException
    {

        if (this.idObjet != v)
        {
            this.idObjet = v;
            setModified(true);
        }


        if (aObjet != null && !(aObjet.getId() == v))
        {
            aObjet = null;
        }

    }

    /**
     * Get the Nom
     *
     * @return String
     */
    public String getNom()
    {
        return nom;
    }


    /**
     * Set the value of Nom
     *
     * @param v new value
     */
    public void setNom(String v) 
    {

        if (!ObjectUtils.equals(this.nom, v))
        {
            this.nom = v;
            setModified(true);
        }


    }

    /**
     * Get the Bonusattaque
     *
     * @return int
     */
    public int getBonusattaque()
    {
        return bonusattaque;
    }


    /**
     * Set the value of Bonusattaque
     *
     * @param v new value
     */
    public void setBonusattaque(int v) 
    {

        if (this.bonusattaque != v)
        {
            this.bonusattaque = v;
            setModified(true);
        }


    }

    /**
     * Get the Bonusdegat
     *
     * @return int
     */
    public int getBonusdegat()
    {
        return bonusdegat;
    }


    /**
     * Set the value of Bonusdegat
     *
     * @param v new value
     */
    public void setBonusdegat(int v) 
    {

        if (this.bonusdegat != v)
        {
            this.bonusdegat = v;
            setModified(true);
        }


    }

    /**
     * Get the Bonusesquive
     *
     * @return int
     */
    public int getBonusesquive()
    {
        return bonusesquive;
    }


    /**
     * Set the value of Bonusesquive
     *
     * @param v new value
     */
    public void setBonusesquive(int v) 
    {

        if (this.bonusesquive != v)
        {
            this.bonusesquive = v;
            setModified(true);
        }


    }

    /**
     * Get the Portee
     *
     * @return int
     */
    public int getPortee()
    {
        return portee;
    }


    /**
     * Set the value of Portee
     *
     * @param v new value
     */
    public void setPortee(int v) 
    {

        if (this.portee != v)
        {
            this.portee = v;
            setModified(true);
        }


    }

    /**
     * Get the Type
     *
     * @return int
     */
    public int getType()
    {
        return type;
    }


    /**
     * Set the value of Type
     *
     * @param v new value
     */
    public void setType(int v) 
    {

        if (this.type != v)
        {
            this.type = v;
            setModified(true);
        }


    }

    



    private Objet aObjet;

    /**
     * Declares an association between this object and a Objet object
     *
     * @param v Objet
     * @throws TorqueException
     */
    public void setObjet(Objet v) throws TorqueException
    {
        if (v == null)
        {
            setIdObjet( 0);
        }
        else
        {
            setIdObjet(v.getId());
        }
        aObjet = v;
    }


    /**
     * Returns the associated Objet object.
     * If it was not retrieved before, the object is retrieved from
     * the database
     *
     * @return the associated Objet object
     * @throws TorqueException
     */
    public Objet getObjet()
        throws TorqueException
    {
        if (aObjet == null && (this.idObjet != 0))
        {
            aObjet = ObjetPeer.retrieveByPK(SimpleKey.keyFor(this.idObjet));
        }
        return aObjet;
    }

    /**
     * Return the associated Objet object
     * If it was not retrieved before, the object is retrieved from
     * the database using the passed connection
     *
     * @param connection the connection used to retrieve the associated object
     *        from the database, if it was not retrieved before
     * @return the associated Objet object
     * @throws TorqueException
     */
    public Objet getObjet(Connection connection)
        throws TorqueException
    {
        if (aObjet == null && (this.idObjet != 0))
        {
            aObjet = ObjetPeer.retrieveByPK(SimpleKey.keyFor(this.idObjet), connection);
        }
        return aObjet;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey, for example
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setObjetKey(ObjectKey key) throws TorqueException
    {

        setIdObjet(((NumberKey) key).intValue());
    }
   
        
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
            fieldNames.add("IdObjet");
            fieldNames.add("Nom");
            fieldNames.add("Bonusattaque");
            fieldNames.add("Bonusdegat");
            fieldNames.add("Bonusesquive");
            fieldNames.add("Portee");
            fieldNames.add("Type");
            fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by field (Java) name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
        if (name.equals("IdObjet"))
        {
            return new Integer(getIdObjet());
        }
        if (name.equals("Nom"))
        {
            return getNom();
        }
        if (name.equals("Bonusattaque"))
        {
            return new Integer(getBonusattaque());
        }
        if (name.equals("Bonusdegat"))
        {
            return new Integer(getBonusdegat());
        }
        if (name.equals("Bonusesquive"))
        {
            return new Integer(getBonusesquive());
        }
        if (name.equals("Portee"))
        {
            return new Integer(getPortee());
        }
        if (name.equals("Type"))
        {
            return new Integer(getType());
        }
        return null;
    }

    /**
     * Set a field in the object by field (Java) name.
     *
     * @param name field name
     * @param value field value
     * @return True if value was set, false if not (invalid name / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByName(String name, Object value )
        throws TorqueException, IllegalArgumentException
    {
        if (name.equals("IdObjet"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setIdObjet(((Integer) value).intValue());
            return true;
        }
        if (name.equals("Nom"))
        {
            // Object fields can be null
            if (value != null && ! String.class.isInstance(value))
            {
                throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
            }
            setNom((String) value);
            return true;
        }
        if (name.equals("Bonusattaque"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setBonusattaque(((Integer) value).intValue());
            return true;
        }
        if (name.equals("Bonusdegat"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setBonusdegat(((Integer) value).intValue());
            return true;
        }
        if (name.equals("Bonusesquive"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setBonusesquive(((Integer) value).intValue());
            return true;
        }
        if (name.equals("Portee"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setPortee(((Integer) value).intValue());
            return true;
        }
        if (name.equals("Type"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setType(((Integer) value).intValue());
            return true;
        }
        return false;
    }

    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
        if (name.equals(ArmePeer.ID_OBJET))
        {
            return new Integer(getIdObjet());
        }
        if (name.equals(ArmePeer.NOM))
        {
            return getNom();
        }
        if (name.equals(ArmePeer.BONUSATTAQUE))
        {
            return new Integer(getBonusattaque());
        }
        if (name.equals(ArmePeer.BONUSDEGAT))
        {
            return new Integer(getBonusdegat());
        }
        if (name.equals(ArmePeer.BONUSESQUIVE))
        {
            return new Integer(getBonusesquive());
        }
        if (name.equals(ArmePeer.PORTEE))
        {
            return new Integer(getPortee());
        }
        if (name.equals(ArmePeer.TYPE))
        {
            return new Integer(getType());
        }
        return null;
    }

    /**
     * Set field values by Peer Field Name
     *
     * @param name field name
     * @param value field value
     * @return True if value was set, false if not (invalid name / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByPeerName(String name, Object value)
        throws TorqueException, IllegalArgumentException
    {
      if (ArmePeer.ID_OBJET.equals(name))
        {
            return setByName("IdObjet", value);
        }
      if (ArmePeer.NOM.equals(name))
        {
            return setByName("Nom", value);
        }
      if (ArmePeer.BONUSATTAQUE.equals(name))
        {
            return setByName("Bonusattaque", value);
        }
      if (ArmePeer.BONUSDEGAT.equals(name))
        {
            return setByName("Bonusdegat", value);
        }
      if (ArmePeer.BONUSESQUIVE.equals(name))
        {
            return setByName("Bonusesquive", value);
        }
      if (ArmePeer.PORTEE.equals(name))
        {
            return setByName("Portee", value);
        }
      if (ArmePeer.TYPE.equals(name))
        {
            return setByName("Type", value);
        }
        return false;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
        if (pos == 0)
        {
            return new Integer(getIdObjet());
        }
        if (pos == 1)
        {
            return getNom();
        }
        if (pos == 2)
        {
            return new Integer(getBonusattaque());
        }
        if (pos == 3)
        {
            return new Integer(getBonusdegat());
        }
        if (pos == 4)
        {
            return new Integer(getBonusesquive());
        }
        if (pos == 5)
        {
            return new Integer(getPortee());
        }
        if (pos == 6)
        {
            return new Integer(getType());
        }
        return null;
    }

    /**
     * Set field values by its position (zero based) in the XML schema.
     *
     * @param position The field position
     * @param value field value
     * @return True if value was set, false if not (invalid position / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByPosition(int position, Object value)
        throws TorqueException, IllegalArgumentException
    {
    if (position == 0)
        {
            return setByName("IdObjet", value);
        }
    if (position == 1)
        {
            return setByName("Nom", value);
        }
    if (position == 2)
        {
            return setByName("Bonusattaque", value);
        }
    if (position == 3)
        {
            return setByName("Bonusdegat", value);
        }
    if (position == 4)
        {
            return setByName("Bonusesquive", value);
        }
    if (position == 5)
        {
            return setByName("Portee", value);
        }
    if (position == 6)
        {
            return setByName("Type", value);
        }
        return false;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
        save(ArmePeer.DATABASE_NAME);
    }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
     *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
        try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
    }

    /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
        if (!alreadyInSave)
        {
            alreadyInSave = true;



            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    ArmePeer.doInsert((Arme) this, con);
                    setNew(false);
                }
                else
                {
                    ArmePeer.doUpdate((Arme) this, con);
                }
            }

            alreadyInSave = false;
        }
    }


    /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param key idObjet ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        throws TorqueException
    {
        setIdObjet(((NumberKey) key).intValue());
    }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
        setIdObjet(Integer.parseInt(key));
    }


    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
        return SimpleKey.keyFor(getIdObjet());
    }
 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     */
    public Arme copy() throws TorqueException
    {
        return copy(true);
    }

    /**
     * Makes a copy of this object using connection.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     *
     * @param con the database connection to read associated objects.
     */
    public Arme copy(Connection con) throws TorqueException
    {
        return copy(true, con);
    }

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * If the parameter deepcopy is true, it then fills all the
     * association collections and sets the related objects to
     * isNew=true.
     *
     * @param deepcopy whether to copy the associated objects.
     */
    public Arme copy(boolean deepcopy) throws TorqueException
    {
        return copyInto(new Arme(), deepcopy);
    }

    /**
     * Makes a copy of this object using connection.
     * It creates a new object filling in the simple attributes.
     * If the parameter deepcopy is true, it then fills all the
     * association collections and sets the related objects to
     * isNew=true.
     *
     * @param deepcopy whether to copy the associated objects.
     * @param con the database connection to read associated objects.
     */
    public Arme copy(boolean deepcopy, Connection con) throws TorqueException
    {
        return copyInto(new Arme(), deepcopy, con);
    }
  
    /**
     * Fills the copyObj with the contents of this object.
     * The associated objects are also copied and treated as new objects.
     *
     * @param copyObj the object to fill.
     */
    protected Arme copyInto(Arme copyObj) throws TorqueException
    {
        return copyInto(copyObj, true);
    }

  
    /**
     * Fills the copyObj with the contents of this object using connection.
     * The associated objects are also copied and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param con the database connection to read associated objects.
     */
    protected Arme copyInto(Arme copyObj, Connection con) throws TorqueException
    {
        return copyInto(copyObj, true, con);
    }
  
    /**
     * Fills the copyObj with the contents of this object.
     * If deepcopy is true, The associated objects are also copied
     * and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param deepcopy whether the associated objects should be copied.
     */
    protected Arme copyInto(Arme copyObj, boolean deepcopy) throws TorqueException
    {
        copyObj.setIdObjet(idObjet);
        copyObj.setNom(nom);
        copyObj.setBonusattaque(bonusattaque);
        copyObj.setBonusdegat(bonusdegat);
        copyObj.setBonusesquive(bonusesquive);
        copyObj.setPortee(portee);
        copyObj.setType(type);

        copyObj.setIdObjet( 0);

        if (deepcopy)
        {
        }
        return copyObj;
    }
        
    
    /**
     * Fills the copyObj with the contents of this object using connection.
     * If deepcopy is true, The associated objects are also copied
     * and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param deepcopy whether the associated objects should be copied.
     * @param con the database connection to read associated objects.
     */
    protected Arme copyInto(Arme copyObj, boolean deepcopy, Connection con) throws TorqueException
    {
        copyObj.setIdObjet(idObjet);
        copyObj.setNom(nom);
        copyObj.setBonusattaque(bonusattaque);
        copyObj.setBonusdegat(bonusdegat);
        copyObj.setBonusesquive(bonusesquive);
        copyObj.setPortee(portee);
        copyObj.setType(type);

        copyObj.setIdObjet( 0);

        if (deepcopy)
        {
        }
        return copyObj;
    }
    
    

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public ArmePeer getPeer()
    {
        return peer;
    }

    /**
     * Retrieves the TableMap object related to this Table data without
     * compiler warnings of using getPeer().getTableMap().
     *
     * @return The associated TableMap object.
     */
    public TableMap getTableMap() throws TorqueException
    {
        return ArmePeer.getTableMap();
    }


    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Arme:\n");
        str.append("IdObjet = ")
           .append(getIdObjet())
           .append("\n");
        str.append("Nom = ")
           .append(getNom())
           .append("\n");
        str.append("Bonusattaque = ")
           .append(getBonusattaque())
           .append("\n");
        str.append("Bonusdegat = ")
           .append(getBonusdegat())
           .append("\n");
        str.append("Bonusesquive = ")
           .append(getBonusesquive())
           .append("\n");
        str.append("Portee = ")
           .append(getPortee())
           .append("\n");
        str.append("Type = ")
           .append(getType())
           .append("\n");
        return(str.toString());
    }
}
